//
//  NewsPaperViewController.m
//  CarHome
//
//  Created by apple on 15/3/23.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "NewsPaperViewController.h"
#import "NewsTableViewCell.h"

@interface NewsPaperViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *tableview;
@property (nonatomic, retain)NewsData *data;

@end

@implementation NewsPaperViewController
- (void)dealloc
{
    [_tableview release];
    [_result release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableview = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:self.tableview];
    [_tableview release];
    self.tableview.dataSource = self;
    self.tableview.delegate = self;
    [self.tableview registerClass:[NewsTableViewCell class] forCellReuseIdentifier:@"reuse"];
    self.data = [[NewsData alloc]init];
    
    [self.tableview addHeaderWithTarget:self action:@selector(headerRefreshing)];
    [self.tableview addFooterWithTarget:self action:@selector(footerReferening)];
    
    
}


- (void)headerRefreshing
{
    [self.tableview reloadData];
    [self.tableview headerEndRefreshing];
    
    
}
- (void)footerReferening
{
    
    [self.tableview footerEndRefreshing];
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[[self.result objectForKey:@"result"] objectForKey:@"newslist"] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    
    [self.data initWithDictionary:[[[self.result objectForKey:@"result"] objectForKey:@"newslist"] objectAtIndex:indexPath.row]];
    cell.data = self.data;
//    NSLog(@"%@", cell.data.idStr);
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
#pragma mark

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
